Solving 10385 - Duathlon (Ternary search)
[and.git] / 541 - Error correction / 541.cpp
blob741c07239836d01432ab4408f07f7ee2d8ccb5ec
1 #include <iostream>
3 using namespace std;
5 int m[100][100];
6 //Contiene 0 si la fila o columna i es par, 1 si es impar
7 bool r[100], c[100];
9 int main(){
10 int n;
11 while (cin >> n && n){
12 for (int i=0; i<n; ++i){
13 for (int j=0; j<n; ++j){
14 cin >> m[i][j];
17 //rows
18 for (int i=0; i<n; ++i){
19 int res = 0;
20 for (int j=0; j<n; ++j){
21 res = (res + m[i][j]) % 2;
23 r[i] = res;
26 //columns
27 for (int j=0; j<n; ++j){
28 int res = 0;
29 for (int i=0; i<n; ++i){
30 res = (res + m[i][j]) % 2;
32 c[j] = res;
35 int oddRows=0, oddCols=0;
37 int x, y;
38 for (int i=0; i<n; ++i){
39 oddRows += r[i];
40 oddCols += c[i];
41 if (r[i]) x = i;
42 if (c[i]) y = i;
44 if (oddRows + oddCols == 0){
45 cout << "OK";
46 }else if (oddRows == 1 && oddCols == 1){
47 cout << "Change bit ("<<x+1<<","<<y+1<<")";
48 }else{
49 cout << "Corrupt";
51 cout << endl;
54 return 0;